using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;

public partial class myfindadoc : System.Web.UI.Page
{
    //Create an Object of Manager class
    Manager manager = new Manager(true,"ConnectionString");
    
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.descriptionContent ="Create your Findadoc profile right here at this page. You can register yourself at Findadoc here either in doctor registration, dentist registration, patient registration depending upon whether you are a doctor, dentist or a patient.";
        Master.titleContent = "Registration For Doctors, Dentists, Patients At Find A Doctor, Ask A Doctor";        
        Master.keywordsContent=" Registration for doctors, registration for dentists, registration for patients, rate doctors, find a doctor, find a dentist, rate dentists, findadoc";
    }

    protected void lnlbtnUserid_Click(object sender, EventArgs e)
    {
        if (Session["userID"] != null && Session["userID"].ToString().Trim() != "")
        {
            // Response.Redirect("Patient/patient_registration.aspx?id=" + Session["userID"].ToString());
            Response.Redirect("User/UserContent.aspx");
        }
    }

    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        #region Clear old values once someone tried to login
        lblError.Text = "";

        Session["userID"] = "";
        Session["userType"] = "";
        Session["LoginName"] = "";
        Session["UserEmail"] = "";
        Session["DoctorType"] = "";
        Session["DentistDoctorEmail"] = "";//Added for Face Page
        #endregion

        localFunction lfunc = new localFunction();
        if (chkremberdoc.Checked)
        {
            lfunc.rememberMe(localFunction.DOCTORCOOKIE, txtDocEmail.Text, txtDocPass.Text);
        }
        else
            lfunc.RemoveCookie(localFunction.DOCTORCOOKIE);

        //  17-11-2007
        //  DEEPAK - CODE MODIFIED TO LET DOCTOR, DENTIST & PATIENT LOGIN FROM SINGLE LOGIN BOX
        //  CODE STARTS

        if (string.Compare(rbtnlDoctorType.SelectedValue, "Doctor", true) == 0) // If Doctor is being logged in
        {
            #region Check Docotor Login
            Doctor doc = new Doctor();
            lblError.Text = doc.DoLogin(txtDocEmail.Text, txtDocPass.Text, "doctor/");
            lblError.Visible = true;
            #endregion
        }
        else if (string.Compare(rbtnlDoctorType.SelectedValue, "Dentist", true) == 0) // If Dentist is being logged in
        {
            #region Check Dentist Login
            clsDentist Dentist = new clsDentist(txtDocEmail.Text);
            //Response.Write(Dentist.ErrorDescription);

            if (!Dentist.HasError)
            {

                if (string.Compare(Dentist.PASSWORD, txtDocPass.Text) == 0)
                {
                    Session["userID"] = Dentist.ID.ToString();
                    Session["userType"] = "Dentist";
                    Session["LoginName"] = Dentist.FNAME + " " + Dentist.LNAME;
                    Session["UserEmail"] = Dentist.EMAIL;
                    Session["DoctorType"] = "Dentist";

                   // Response.Redirect("Dentist/DentistContent.aspx", true);
                    Response.Redirect(Session["strHttps"].ToString() + "Dentist/DentistContent.aspx", true);
                }
                else
                {
                    lblError.Text = "Invalid Password";
                    lblError.Visible = true;
                }
            }
            else if (string.Compare(Dentist.ErrorDescription, "Dentist not found!", true) == 0)
            {
                lblError.Text = "Your login information is incorrect.";
                lblError.Visible = true;
            }
            #endregion
        }
        else
        {
            // PATIENT LOGIN CHECK - INCORPORATED FROM PHASE IV ON 17-11-2007 - DEEPAK
            string strSql = " Select ID,fName,Mname,LName,Password FROM tbl_Users where Email='" + manager.FixQuote(txtDocEmail.Text) + "' and isdelete=0";
            SqlDataReader sqlDr = manager.ExecuteQuery(strSql);
            if (sqlDr.Read())
            {
                if (string.Compare(sqlDr["Password"].ToString(), txtDocPass.Text, false) == 0)
                {
                    Session["userID"] = sqlDr["id"].ToString();
                    Session["userType"] = "SiteUser";
                    Session["LoginName"] = sqlDr["fName"].ToString() + " " + sqlDr["Mname"].ToString() + " " + sqlDr["LName"].ToString();
                    Session["UserEmail"] = txtDocEmail.Text;
                    Session["DoctorType"] = "User";

                    if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["fromPg"]))
                        HttpContext.Current.Response.Redirect(HttpContext.Current.Request.QueryString["fromPg"]);

                    Response.Redirect(Session["strHttp"] + "default.aspx");
                }
                else
                {
                    lblError.Text = "Invalid Password";
                    lblError.Visible = true;
                }
            }
            else
            {
                lblError.Text = "Your login information is incorrect.";
                lblError.Visible = true;
            }
        }

        #region If any user is logged in then show Logout Link
        if (!Equals(Session["userID"], null) && Session["userID"].ToString().Length > 0)
        {
            ((LinkButton)Master.FindControl("lnk_log")).Text = "Logout";
        }
        #endregion
    }

    protected void lnkbtnRegistration_Click(object sender, EventArgs e)
    {
        if (string.Compare(rbtnlDoctorType.SelectedValue, "Doctor", true) == 0) // If Doctor - Access Profile
        {
            Response.Redirect(Session["strHttps"].ToString()+"doctor/doctorRegistration.aspx");
        }
        else
        {
            Response.Redirect(Session["strHttps"].ToString()+"Dentist/DentistRegistration.aspx");
        }
    }

    protected void lnkbtnForgetPass_Click(object sender, EventArgs e)
    {
        if (string.Compare(rbtnlDoctorType.SelectedValue, "Doctor", true) == 0) // If Doctor - Access Profile
        {
            Response.Redirect("doctor/doctorForgotPass.aspx");
        }
        else
        {
            Response.Redirect("Dentist/DentistForgotPass.aspx");
        }

    }

    protected void lnkbtnAccessProfile_Click(object sender, EventArgs e)
    {
        if (string.Compare(rbtnlDoctorType.SelectedValue, "Doctor", true) == 0) // If Doctor - Access Profile
        {
            Response.Redirect(Session["strHttps"].ToString()+"doctor/AccessProfile.aspx");
        }
        else
        {
            Response.Redirect(Session["strHttps"].ToString()+"Dentist/DentistAccessProfile.aspx");
        }
    }
}
